//
//  CountyCityViewController.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/4/26.
//  Copyright © 2018年 Lwx. All rights reserved.
//

#import "CountyCityViewController.h"
#import "HomeViewController.h"
#import "TravelDateViewController.h"
@interface CountyCityViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)UITableView * tableView;
@end

@implementation CountyCityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    
    
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [UIView new];
    }return _tableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.countyCityArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
        
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
        cell.backgroundColor = [UIColor clearColor];
        cell.contentView.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell.textLabel setTextColor:[UIColor blackColor]];
        cell.textLabel.font = [UIFont systemFontOfSize:18];
    }
    
    cell.textLabel.text = self.countyCityArr[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.isCollectionHidden == YES) {
        for (UIViewController *controller in self.navigationController.viewControllers) {
            if ([controller isKindOfClass:[HomeViewController class]]) {
                [[NSNotificationCenter defaultCenter]postNotificationName:@"getLocation" object:nil userInfo:@{@"chooseLocation":self.countyCityArr[indexPath.row]}];
                HomeViewController *homeVC =(HomeViewController *)controller;
                [self.navigationController popToViewController:homeVC animated:YES];
            }
        }
    }else{
        TravelDateViewController *vc = [[TravelDateViewController alloc]init];
        vc.city = self.countyCityArr[indexPath.row];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
@end
